﻿using Ease.EaseDialog.Runtime;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace Ease.EaseDialog.Scripts.Editor
{
    public class DialogMenu
    {
        [MenuItem("Tools/Dialog")]
        public static void ShowEW()
        {
            DialogEW wnd = EditorWindow.GetWindow<DialogEW>();
            wnd.titleContent = new GUIContent("Dialog编辑器");
        }

        [OnOpenAsset(1)]
        private static bool DoubleClickToOpenWindow(int instanceID, int line)
        {
            var obj = EditorUtility.InstanceIDToObject(instanceID);
            string path = AssetDatabase.GetAssetPath(obj);
            if (obj is DialogDataSo)
            {
                DialogEW[] windows = Resources.FindObjectsOfTypeAll<DialogEW>();
                if (windows.Length > 0)
                {
                    Debug.LogError("窗口已经打开");
                    return false;
                }

                ShowEW();
                return true;
            }

            return false;
        }
    }
}